<template>
  <div id="bannedUsersTopSearch">
    <h1 class="con-right-title">
      用户禁言
    </h1>
    <div class="search-box">
      <!-- 大鹏号 -->
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="大鹏号" prop="dpAccount">
          <el-input
            v-model="formInline.dpAccount"
            placeholder="请输入大鹏号"
          ></el-input>
        </el-form-item>

        <!-- 未通过内容数 -->
        <el-form-item label="未通过内容数" prop="sort">
          <el-select
            placeholder="请选择未通过内容数"
            clearable
            v-model="formInline.sort"
          >
            <el-option
              v-for="item in Failposts"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <!-- 被禁言次数 -->
        <el-form-item label="被禁言次数" prop="numberOfProhibitions">
          <el-select
            placeholder="请选择被禁言次数"
            clearable
            v-model="formInline.numberOfProhibitions"
          >
            <el-option
              v-for="item in bannedNumber"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <!-- 禁言状态 -->
        <el-form-item label="禁言状态" prop="state">
          <el-select
            placeholder="请选择禁言状态"
            clearable
            v-model="formInline.state"
          >
            <el-option
              v-for="item in State"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <!-- 禁言时长 -->
        <el-form-item label="当前禁言时长" prop="compare">
          <el-select
            placeholder="请选择当前禁言时长"
            clearable
            v-model="formInline.compare"
          >
            <el-option
              v-for="item in Forbidden"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <!-- 禁言时间 -->
        <el-form-item label="禁言时间" prop="shutTime">
          <el-date-picker
            v-model="formInline.shutTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            class="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="shupUpTime"
          >
          </el-date-picker>
        </el-form-item>

        <!-- 审核人 -->
        <el-form-item label="审核人" prop="reviewer">
          <el-select
            filterable
            placeholder="请选择审核人"
            clearable
            v-model="formInline.reviewer"
          >
            <el-option
              v-for="(item, index) in Spare"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getDpNum } from '@/api/system/user'
export default {
  name: 'bannedUsersTopSearch',
  msg: '评论审核-用户禁言-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          shutTime: [],
          compare: '', //当前禁言时长
          dpAccount: '', //大鹏号
          endTime: '', //结束时间
          numberOfProhibitions: '', //被禁言次数
          reviewer: '', //审核人
          sort: 'DESC', //审核不通过次数排序
          startTime: '', // 开始时间
          state: '' //禁言状态
        }
      }
    }
  },

  data() {
    return {
      Failposts: [],
      bannedNumber: [],
      State: [],
      Forbidden: [],
      Spare: [],
      rules: {
        compare: {},
        dpAccount: {},
        numberOfProhibitions: {},
        sort: {},
        shutTime: [],
        state: {}
      }
    }
  },

  mounted() {
    this.getCheckUser()
  },

  async created() {
    let [data, data2, data3, data4] = await Promise.all([
      sysNormalDisable('banned_number_of_prohibitions'),
      sysNormalDisable('banned_state'),
      sysNormalDisable('banned_sort'),
      sysNormalDisable('banned_compare')
    ])
    //被禁言次数
    this.bannedNumber = this.bannedNumber.concat(data)
    //禁言状态
    this.State = this.State.concat(data2)
    //排序
    this.Failposts = this.Failposts.concat(data3)
    //禁言时长
    this.Forbidden = this.Forbidden.concat(data4)
  },
  methods: {
    shupUpTime(time) {
      if(!time){
        this.formInline.startTime = ''
        this.formInline.endTime = ''
      }else{
         this.formInline.startTime = time[0]
         this.formInline.endTime = time[1]
      }
    },
    // 审核人
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.Spare = this.Spare.concat(response)
      })
    },

    //搜索
    toSearch() {
      this.$emit('toSearch')
    },

    //重置
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.formInline.endTime = ''
      this.formInline.startTime = ''
    }
  }
}
</script>
